package com.bilin.coin.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.bilin.coin.R;
import com.bilin.coin.bean.BuyRecordBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.list.BuyRecordList;
import com.bilin.coin.tools.AlertUtils;
import com.bilin.coin.tools.Poster;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;


@Route(path = "/mall/BuyRecordListActivity")
public class BuyRecordListActivity extends BaseAppCompatActivity {

    @BindView(R.id.ll_main)
    LinearLayout ll_main;

    BuyRecordList financialIncomeList;
    BaseQuickAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void initView() {
        setTitle("购买记录");
        financialIncomeList = new BuyRecordList(this);
        financialIncomeList.refresh(true);
        ll_main.addView(financialIncomeList.getRootView());
        adapter = financialIncomeList.getAdapter();
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                BuyRecordBean.RecordsBean item = (BuyRecordBean.RecordsBean)adapter.getData().get(position);
                String device = "";
                switch (item.getDevice()) {
                    case "1":
                        device = "推车";
                        break;
                    case "2":
                        device = "小挖机";
                        break;
                    case "3":
                        device = "运煤车";
                        break;
                    case "4":
                        device = "大挖机";
                        break;
                }
                AlertUtils.dialog2(BuyRecordListActivity.this, "尊敬的用户您好，", "您确定退租您的设备："+device+"？退租后预计可得"+item.getRefundMoney()+",进入到钱包账户请及时签收。", new AlertUtils.OnPositiveClick() {
                    @Override
                    public void onClick() {
                        refund(item.getId());
                    }
                });
            }
        });
    }

    private void refund(String id) {
        new Poster(this, true, true) {
            @Override
            protected String fillUrl() {
                return "/api/buy-log/refund";
            }

            @Override
            protected Map<String, String> fillParams() {
                HashMap hashMap = new HashMap();
                hashMap.put("id", id);
                return hashMap;
            }

            @Override
            protected void disposeSuccess(String dataJson) {
                super.disposeSuccess(dataJson);
                financialIncomeList.refresh(true);
            }
        };
    }

    @Override
    protected void initData() {

    }


    @Override
    protected int getLayoutId() {
        return R.layout.common_layout;
    }



}
